
#include "Context/Gameplay/Game.h"
#include "Context/Gameplay/Track.h"
#include "Context/Gameplay/Car.h"
#include "Context/Gameplay/PlayerDriver.h"
#include "Context/Gameplay/AIDriver.h"


#include <cmath>

namespace Context {

 Game::Game()
	: Engine::Visual("Gameplay")
	, Engine::Reason("Gameplay")
	, Engine::Sense("Gameplay")
 {
	track = new Track("newTestTrack");
	racers.push_back(new Context::Car("pacman", track, new Context::PlayerDriver()));
}

// Asks for generation of a graphical model to be displayed
Engine::Resource::GraphicList Game::display() {
	Engine::Resource::GraphicList gfxList;
	return gfxList;
}

void Game::pulse(int delta) {
	/* Get player information */
	/* Update camera with player information */
	Misc::Frame & camera =	Engine::Renderer::camera;
 	camera.centralizeAt(nearbyint(racers.front()->position.x), nearbyint(racers.front()->position.y));
	//std::printf("racer: %f %f, camera: %d %d\n", racers.front()->position.x, racers.front()->position.y, camera.x, camera.y);
	if (camera.x < 0) camera.x = 0;
	if (camera.y < 0) camera.y = 0;
	if (camera.x + camera.w > track->readSize().x) { camera.x = track->readSize().x - camera.w; }
	if (camera.y + camera.h > track->readSize().y) { camera.y = track->readSize().y - camera.h; }
}


} // namespace Context
